﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StarClub.BLL
{
    /// <summary>
    /// 用户密码管理业务逻辑类
    /// </summary>
    public class PassWordManage
    {
        /// <summary>
        /// 更改用户密码
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="oldPwd">旧密码</param>
        /// <param name="newPwd">新密码</param>
        /// <param name="newPwdRe">重复新密码</param>
        /// <param name="msg">返回的消息</param>
        /// <returns></returns>
        public bool ChangePassWord(int uid, string oldPwd, string newPwd, string newPwdRe, out string msg)
        {
            msg = string.Empty;
            if (oldPwd == "" || newPwd == "" || newPwdRe == "")
            {
                msg = "请完整填写";
                return false;
            }
            StarClub.DAL.star_user dal = new StarClub.DAL.star_user();
            string _oldPwd = dal.GetUserPassWord(uid);
            if (_oldPwd != Common.Md5.ToMd5(oldPwd))
            {
                msg = "旧密码不正确";
                return false;
            }
            if (newPwd != newPwdRe)
            {
                msg = "两次输入的新密码不相同";
                return false;
            }
            if (dal.UpdatePassWord(uid, Common.Md5.ToMd5(newPwd)) < 1)
            {
                msg = "更新密码出错";
                return false;
            }
            return true;
        }
    }
}
